'''
Created on 20/04/2012

@author: joan
'''
#from google.appengine.ext import webapp

from backend.busca_palabra import DicEsp
import django

import webapp2

import os
from cgi import escape


voc =os.path.join(os.path.dirname(__file__),"backend/dic/spanish.clean")

bp = DicEsp(voc)

#import jinja2
#
#jinja_environment = jinja2.Environment(
#    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))

from google.appengine.ext.webapp import template
class MisApalabrados(webapp2.RequestHandler):
    '''
    classdocs
    '''
    

    
    def get(self):
        
        #self.response.headers['Content-Type'] = 'text/plain'
        #self.response.out.write('Hello, Bienvenido a mis apalabrados!!')
        
        msg = "Hay %d"%len(bp.dwords);
        #self.response.out.write(msg)
        
        #self.response.out.write(self.request.get('p'))
        query = self.request.get('query',default_value="")
    
        if query == "":
    
            path = os.path.join(os.path.dirname(__file__), 'templates/mobile/app.html')
            
            
        
            self.response.out.write(template.render(path,{}))
        else:
            letters = escape(query).lower()
            lwords = bp.returnWords(letters)
            path = os.path.join(os.path.dirname(__file__), 'templates/mobile/mlistwords.html')
            
            params = {"lwords":lwords}
            self.response.out.write(template.render(path,params))
        
    
    
